package com.yugao.fintech.draper.admin.controller;

import com.yugao.fintech.draper.admin.param.DeptDTO;
import com.yugao.fintech.draper.admin.service.DeptService;
import com.yugao.fintech.draper.core.model.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dept")
@RequiredArgsConstructor
@Tag(name = "系统部门管理")
public class DeptController {

    private final DeptService deptService;

    @Operation(summary = "获取部门树")
    @GetMapping("/getDeptTree")
    public ResultVO<DeptDTO> getDeptTree() {
        return ResultVO.success(deptService.getDeptTree());
    }

    @Operation(summary = "保存部门信息")

    @PostMapping("/addDept")
    public ResultVO<Boolean> addDept(@RequestBody DeptDTO deptDTO) {
        return ResultVO.success(deptService.addDept(deptDTO));
    }

    @Operation(summary = "更新部门信息")

    @PutMapping("/updateDept")
    public ResultVO<Boolean> updateDept(@RequestBody DeptDTO deptDTO) {
        return ResultVO.success(deptService.updateById(deptDTO));
    }

    @Operation(summary = "根据id删除部门")
    @DeleteMapping("/deleteById/{id}")
    public ResultVO<Boolean> deleteById(@PathVariable("id") Long id) {
        return ResultVO.success(deptService.deleteById(id));
    }

    @Operation(summary = "根据id获取部门数据")
    @GetMapping("/finBydDeptId/{id}")
    public ResultVO<DeptDTO> finBydDeptId(@PathVariable("id") Long id) {
        return ResultVO.success(deptService.finBydDeptId(id));
    }

    @Operation(summary = "获取当前用户部门(包含父级)")
    @GetMapping("/getDeptNameByUserId")
    public ResultVO<String> getDeptNameByUserId() {
        return ResultVO.success(deptService.getDeptNameByUserId());
    }

}
